package com.jsh.erp.cloud.api;

import com.jsh.erp.cloud.service.DepotHeadApiService;
import com.jsh.erp.datasource.entities.DepotHead;
import com.jsh.erp.service.depotHead.DepotHeadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/api/depotHead")
@Slf4j
public class DepotHeadApi {
    @Resource
    private DepotHeadApiService depotHeadApiService;
    @Resource
    private DepotHeadService depotHeadService;

    @GetMapping("/getAccountSum")
    public BigDecimal getAccountSum(Long accountId,
                                    String timeStr,
                                    String type) throws Exception {
        return depotHeadApiService.getAccountSum(accountId, timeStr, type);
    }

    @GetMapping("/getManyAccountSum")
    public BigDecimal getManyAccountSum(Long accountId,
                                        String timeStr,
                                        String type) throws Exception {
        return depotHeadApiService.getManyAccountSum(accountId, timeStr, type);
    }

    @GetMapping("/getDepotHeadListByAccountIds")
    public List<DepotHead> getDepotHeadListByAccountIds(@RequestParam("accountIds") String[] accountIds) {
        List<DepotHead> list = depotHeadApiService.getDepotHeadListByAccountIds(accountIds);
        if (log.isDebugEnabled()) {
            log.debug("depotHeadList:{},{}", Arrays.asList(accountIds), list);
        }
        return list;
    }

    @GetMapping("/getByAccountId")
    public List<DepotHead> getByAccountId(@RequestParam(name = "accountId", required = false)Long accountId) {
        return depotHeadApiService.getByAccountId(accountId);
    }

    @GetMapping("/getDepotHead")
    public DepotHead getDepotHead(@RequestParam("number") String number) throws Exception {
        return depotHeadService.getDepotHead(number);
    }
}
